package com.example.dialogfragmentlibrary;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import com.example.dialogfragmentlibrary.library.ViewHolder;
import com.example.dialogfragmentlibrary.library2.CustomDialogFragment;
import com.example.dialogfragmentlibrary.library2.OnConvertViewListener;

import java.util.Random;

/**
 * 来自 ：
 * https://github.com/Ablexq/NiceDialog
 */
public class DFDemoActivity2 extends AppCompatActivity {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_fragment);

    }

    public void showDialog0(final View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.share_layout)
                .dimAmount(0.3f)
                .gravity(Gravity.BOTTOM)
                .listener(new OnConvertViewListener() {

                    @Override
                    public void onConvertView(ViewHolder viewHolder, DialogFragment customDialogFragment) {
                        Toast.makeText(DFDemoActivity2.this, "分享成功1111111", Toast.LENGTH_SHORT).show();
                        viewHolder.setOnClickListener(R.id.wechat, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Toast.makeText(DFDemoActivity2.this, "分享成功222222222222", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                })
                .build()
                .show(getSupportFragmentManager());
    }

    public void showDialog1(View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.friend_set_layout)
                .listener(new OnConvertViewListener() {
                    @Override
                    public void onConvertView(ViewHolder viewHolder, DialogFragment customDialogFragment) {

                    }
                })
                .gravity(Gravity.BOTTOM)
                .height(310)
                .build()
                .show(getSupportFragmentManager());
    }

    public void showDialog2(View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.commit_layout)
                .gravity(Gravity.BOTTOM)
                .listener(new OnConvertViewListener() {

                    @Override
                    public void onConvertView(ViewHolder viewHolder, DialogFragment customDialogFragment) {
                        final EditText editText = viewHolder.getView(R.id.edit_input);
                        editText.post(new Runnable() {
                            @Override
                            public void run() {
                                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                imm.showSoftInput(editText, 0);
                            }
                        });
                    }
                })
                .build()
                .show(getSupportFragmentManager());
    }

    public void showDialog3(final View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.ad_layout)
                .width(210)
                .animStyle(R.style.EnterExitAnimation)
                .outCancel(false)
                .listener(new OnConvertViewListener() {
                    @Override
                    public void onConvertView(ViewHolder viewHolder, final DialogFragment dialog) {
                        viewHolder.setOnClickListener(R.id.close, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });
                    }
                })
                .build()
                .show(getSupportFragmentManager());
    }

    public void showDialog4(View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.loading_layout)
                .theme(R.style.MyDialog)
                .width(100)
                .height(100)
                .dimAmount(0)
                .build()
                .show(getSupportFragmentManager());
    }

    public void showDialog5(View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.confirm_layout)
                .margin(60)
                .outCancel(false)
                .listener(new OnConvertViewListener() {

                    @Override
                    public void onConvertView(ViewHolder holder, final DialogFragment dialog) {
                        holder.setText(R.id.title, "提示" + new Random().nextInt(100));
                        holder.setText(R.id.message, "您已支付成功！" + new Random().nextInt(100));
                        holder.setOnClickListener(R.id.cancel, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();

                            }
                        });

                        holder.setOnClickListener(R.id.ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });
                    }
                })
                .build()
                .show(getSupportFragmentManager());
    }

    public void showDialog6(View view) {
        new CustomDialogFragment.Builder()
                .layoutId(R.layout.confirm_layout)
                .margin(60)
                .outCancel(false)
                .listener(new OnConvertViewListener() {

                    @Override
                    public void onConvertView(ViewHolder holder, final DialogFragment dialog) {
                        holder.setText(R.id.title, "警告" + new Random().nextInt(100));
                        holder.setText(R.id.message, "您的账号已被冻结！" + new Random().nextInt(100));
                        holder.setOnClickListener(R.id.cancel, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();

                            }
                        });

                        holder.setOnClickListener(R.id.ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });
                    }
                })
                .build()
                .show(getSupportFragmentManager());
    }
}
